package com.qf.ems.controller;

import com.qf.ems.entity.Emp;
import com.qf.ems.service.EmpService;
import com.qf.ems.service.impl.EmpServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/manager/safe/updateEmp")
public class UpdateEmpController extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //从请求当中获取参数：id，name，salary，age
        Integer id = Integer.valueOf(req.getParameter("id"));
        String name = req.getParameter("name");
        Double salary = Double.valueOf(req.getParameter("salary"));
        Integer age = Integer.valueOf(req.getParameter("age"));
        //创建EMP对象
        Emp emp = new Emp(id, name, salary, age);
        //调用service方法进行修改
        EmpService empService = new EmpServiceImpl();
        empService.modifyEmp(emp);
        //跳转详情页面
        resp.sendRedirect(req.getContextPath()+"/manager/safe/showAllEmp");
    }
}
